﻿Imports System.IO
Imports System.Xml
Imports System.Text

Public Class BlockThreeHomeworkSectionFour
    Dim QuestionNumber As Integer
    Dim dtmTest, dtmTest2 As Date
    Dim filename As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    'Declare the Array as 10 rows and 3 columns
    Dim ArrayMax As Integer = 16 'One number past the end of actual info in array
    Dim HWQuestions(ArrayMax, 3) As String
    Dim intResponse As Integer
    Dim intQuestionCount As Integer = 0
    Dim intAnswerCount As Integer = 0
    Dim intReferenceCount As Integer = 0
    Dim intFirstRun As Integer = 1
    Dim strUser As String = "Enter Last Name"
    Dim strAnswer, strAnswer2, strAnswer3, strAnswer4, strAnswer5, _
     strAnswer6, strAnswer7, strAnswer8, strAnswer9, strAnswer10, strAnswer11, _
     strAnswer12, strAnswer13, strAnswer14, strAnswer15, strAnswer16, strAnswer17, _
     strAnswer18, strAnswer19, strAnswer20, strAnswer21, strAnswer22, strAnswer23, _
     strAnswer24, strAnswer25, strAnswer26, strAnswer27, strAnswer28, strAnswer29, _
     strAnswer30, strAnswer31, strAnswer32, strAnswer33, strAnswer34, strAnswer35, _
     strAnswer36, strAnswer37, strAnswer38, strAnswer39, strAnswer40, strAnswer41, _
     strAnswer42, strAnswer43, strAnswer44, strAnswer45, strAnswer46, strAnswer47, _
     strAnswer48, strAnswer49, strAnswer50, strAnswer51, strAnswer52, strAnswer53, _
     strAnswer54, strAnswer55, strAnswer56, strAnswer57 As String
    Dim intChoiceACount As Integer = 2
    Dim intChoiceBCount As Integer = 3
    Dim intChoiceCCount As Integer = 4
    Dim intChoiceDCount As Integer = 5

    Shared Property MidiParent As MainForm

    Private Sub CloseToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub BlockThreeHomeworkSectionFour_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtObj.Text = "Objectives:" + vbCrLf + "- Given proper student instructional materials, identify characteristics of the AN/GRT-21 and AN/GRT-22."
        If (System.IO.File.Exists(filename & "\Homework\Block 3\Block 3 Section 4.txt")) Then
            intResponse = MsgBox("This assignment has already been completed.  Are you sure you want to delete the current assignment and reaccomplish it?", 4, "Confirm Assignment Deletion")
            If intResponse = MsgBoxResult.Yes Then
                System.IO.File.Delete(filename & "\Homework\Block 3\Block 3 Section 4.txt")
                System.IO.File.Create(filename & "\Homework\Block 3\Block 3 Section 4.txt").Dispose()
            ElseIf intResponse = MsgBoxResult.No Then
                Me.Close()
            End If
        End If
        If (Not System.IO.File.Exists(filename & "\Homework\Block 3\Block 3 Section 4.txt")) Then
            System.IO.File.Create(filename & "\Homework\Block 3\Block 3 Section 4.txt").Dispose()
        End If
        If (Not System.IO.File.Exists(filename & "\Instructor\Block 3\Block 3 Section 4.txt")) Then
            System.IO.File.Create(filename & "\Instructor\Block 3\Block 3 Section 4.txt").Dispose()
        End If
        strUser = InputBox("Please enter last name", strUser)
        If strUser Is "" Then
            Me.Close()
        End If
        '************************************************
        '****** Questions Are Loaded Here****************
        '******* Column 1 is Questions (Preloaded)*******
        '******* Column 2 is Accepts Students Answer*****
        '******* Column 3 is Reference ******************
        HWQuestions(1, 1) = ""
        HWQuestions(1, 2) = strAnswer
        HWQuestions(1, 3) = ""

        HWQuestions(2, 1) = ""
        HWQuestions(2, 2) = strAnswer2
        HWQuestions(2, 3) = ""

        HWQuestions(3, 1) = ""
        HWQuestions(3, 2) = strAnswer3
        HWQuestions(3, 3) = ""

        HWQuestions(4, 1) = ""
        HWQuestions(4, 2) = ""
        HWQuestions(4, 3) = ""

        HWQuestions(5, 1) = ""
        HWQuestions(5, 2) = strAnswer5
        HWQuestions(5, 3) = ""

        HWQuestions(6, 1) = ""
        HWQuestions(6, 2) = strAnswer6
        HWQuestions(6, 3) = ""

        HWQuestions(7, 1) = ""
        HWQuestions(7, 2) = strAnswer7
        HWQuestions(7, 3) = ""

        HWQuestions(8, 1) = ""
        HWQuestions(8, 2) = strAnswer8
        HWQuestions(8, 3) = ""

        HWQuestions(9, 1) = ""
        HWQuestions(9, 2) = strAnswer9
        HWQuestions(9, 3) = ""

        HWQuestions(10, 1) = ""
        HWQuestions(10, 2) = strAnswer10
        HWQuestions(10, 3) = ""

        HWQuestions(11, 1) = ""
        HWQuestions(11, 2) = strAnswer11
        HWQuestions(11, 3) = ""

        HWQuestions(12, 1) = ""
        HWQuestions(12, 2) = strAnswer12
        HWQuestions(12, 3) = ""

        HWQuestions(13, 1) = ""
        HWQuestions(13, 2) = strAnswer13
        HWQuestions(13, 3) = ""

        HWQuestions(14, 1) = ""
        HWQuestions(14, 2) = strAnswer14
        HWQuestions(14, 3) = ""

        HWQuestions(15, 1) = ""
        HWQuestions(15, 2) = strAnswer15
        HWQuestions(15, 3) = ""

        HWQuestions(16, 1) = "Close"
        writeXmlData()
        Next_Question(HWQuestions)
    End Sub

    Private Sub btnNextQuestion_Click(sender As System.Object, e As System.EventArgs) Handles btnNextQuestion.Click
        Next_Question(HWQuestions)
    End Sub
    Private Sub Clear_Display()
        txtQuestion.Clear()
        txtAnswer.Clear()
    End Sub

    Public Function Next_Question(HWQuestions As String(,))
        txtAnswer.Focus()
        If intQuestionCount > 0 Then
            WriteToFile()
        End If
        If btnNextQuestion.Text = "Done" Then
            Me.Close()
            OpenResults()
        End If
        intQuestionCount = intQuestionCount + 1
        LabelChangeCheck()
        If intQuestionCount = 15 Then
            btnNextQuestion.Text = "Done"
        End If
        If intQuestionCount = 1 Or intQuestionCount = 2 Or intQuestionCount = 3 Or intQuestionCount = 5 Or intQuestionCount = 6 _
            Or intQuestionCount = 7 Or intQuestionCount = 8 Or intQuestionCount = 9 Or intQuestionCount = 10 Or intQuestionCount = 11 _
            Or intQuestionCount = 12 Or intQuestionCount = 13 Then
            lblQuestion.Text = "Question"
            Matching2.Visible = False
            Matching3.Visible = False
            tblQ4.Visible = False
            lblAnswer.Visible = True
            txtAnswer.Visible = True
            txtQuestion.Text = HWQuestions(intQuestionCount, 1)
            intAnswerCount = intAnswerCount + 1
            HWQuestions(intAnswerCount, 2) = txtAnswer.Text
            intReferenceCount = intReferenceCount + 1
            txtReference.Text = HWQuestions(intReferenceCount, 3)
        End If
        If intQuestionCount = 4 Then
            tblQ4.Visible = True
            Matching2.Visible = False
            Matching3.Visible = False
            lblAnswer.Visible = False
            txtAnswer.Visible = False
            lblQuestion.Text = "Instructions"
            txtQuestion.Text = HWQuestions(intQuestionCount, 1)
        ElseIf intQuestionCount = 14 Then
            tblQ4.Visible = False
            Matching2.Visible = True
            Matching3.Visible = False
            lblAnswer.Visible = False
            txtAnswer.Visible = False
            lblQuestion.Text = "Instructions"
            txtQuestion.Text = HWQuestions(intQuestionCount, 1)
        ElseIf intQuestionCount = 15 Then
            tblQ4.Visible = False
            Matching2.Visible = False
            Matching3.Visible = True
            lblAnswer.Visible = False
            txtAnswer.Visible = False
            lblQuestion.Text = "Instructions"
            txtQuestion.Text = HWQuestions(intQuestionCount, 1)
        End If
        Return intQuestionCount & intAnswerCount
    End Function

    Private Sub LabelChangeCheck()
        If intQuestionCount = 1 Then
            lblSubject.Text = "Review Exercise 4-1"
        ElseIf intQuestionCount = 14 Then
            lblSubject.Text = "Review Exercise 4-2"
        ElseIf intQuestionCount = 15 Then
            lblSubject.Text = "Review Exercise 4-3"
        End If
    End Sub

    Private Sub WriteToFile()
        Dim Integrity As String = (filename & "\Instructor\Block 3\Block 3 Section 4.txt")
        Dim Results As String = (filename & "\Homework\Block 3\Block 3 Section 4.txt")

        '***********Output to hidden file for Instructor Check***********
        If System.IO.File.Exists(Integrity) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Integrity, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine("- " & txtObj.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.WriteLine("Question:" & txtQuestion.Text)
            hiddenWriter.WriteLine("Answer:" & txtAnswer.Text)
            hiddenWriter.WriteLine("Reference: " & txtReference.Text)
            hiddenWriter.WriteLine()
            If intQuestionCount = 15 Then
                hiddenWriter.WriteLine("Block 3 Section 4 Homework Complete")
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.Close()

            'MsgBox("Text written to file")
        Else
            MsgBox("File Does Not Exist Integrity")
        End If

        '******Output to file for Student to review***********
        If System.IO.File.Exists(Results) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Results, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine("- " & txtObj.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
                'hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                'hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            If intQuestionCount = 4 Then
                hiddenWriter.WriteLine("AN/GRT-21")
                hiddenWriter.WriteLine("Frequency Range:  " & txt21FR.Text)
                hiddenWriter.WriteLine("Number of Channels:  " & txt21NC.Text)
                hiddenWriter.WriteLine("Channel Spacing:  " & txt21CS.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("AN/GRT-22")
                hiddenWriter.WriteLine("Frequency Range:  " & txt22FR.Text)
                hiddenWriter.WriteLine("Number of Channels:  " & txt22NC.Text)
                hiddenWriter.WriteLine("Channel Spacing:  " & txt22CS.Text)
                hiddenWriter.WriteLine()
            ElseIf intQuestionCount <> 4 And Matching2.Visible = False And Matching3.Visible = False Then
                hiddenWriter.WriteLine("Question:  " & txtQuestion.Text)
                hiddenWriter.WriteLine("Answer:  " & txtAnswer.Text)
            ElseIf intQuestionCount = 14 Then
                hiddenWriter.WriteLine("Question:  " & txtQuestion.Text)
                hiddenWriter.WriteLine(lblColumnC1.Text & ":  " & TextBox1.Text & vbTab & vbTab & vbTab & lblColumnD1.Text)
                hiddenWriter.WriteLine(lblColumnC2.Text & ":  " & TextBox2.Text & vbTab & vbTab & vbTab & lblColumnD2.Text)
                hiddenWriter.WriteLine(lblColumnC3.Text & ":  " & TextBox3.Text & vbTab & vbTab & vbTab & lblColumnD3.Text)
                hiddenWriter.WriteLine(lblColumnC4.Text & ":  " & TextBox4.Text & vbTab & vbTab & vbTab & lblColumnD4.Text)
                hiddenWriter.WriteLine(lblColumnC5.Text & ":  " & TextBox5.Text & vbTab & vbTab & vbTab & lblColumnD5.Text)
                hiddenWriter.WriteLine(lblColumnC6.Text & ":  " & TextBox6.Text & vbTab & vbTab & lblColumnD6.Text)
                hiddenWriter.WriteLine(lblColumnC7.Text & ":  " & TextBox7.Text & vbTab & vbTab & lblColumnD7.Text)
                hiddenWriter.WriteLine(lblColumnC8.Text & ":  " & TextBox8.Text & vbTab & vbTab & lblColumnD8.Text)
                hiddenWriter.WriteLine(lblColumnC9.Text & ":  " & TextBox9.Text & vbTab & vbTab & lblColumnD9.Text)
                hiddenWriter.WriteLine(lblColumnC10.Text & ":  " & TextBox10.Text & vbTab & vbTab & vbTab & lblColumnD10.Text)
                hiddenWriter.WriteLine(lblColumnC11.Text & ":  " & TextBox11.Text & vbTab & vbTab & lblColumnD11.Text)
                hiddenWriter.WriteLine(lblColumnC12.Text & ":  " & TextBox12.Text & vbTab & lblColumnD12.Text)
                hiddenWriter.WriteLine(lblColumnC13.Text & ":  " & TextBox13.Text & vbTab & vbTab & vbTab & lblColumnD13.Text)
                hiddenWriter.WriteLine(lblColumnC14.Text & ":  " & TextBox14.Text & vbTab & vbTab & vbTab & lblColumnD14.Text)
                hiddenWriter.WriteLine(lblColumnC15.Text & ":  " & TextBox15.Text & vbTab & vbTab & vbTab & lblColumnD15.Text)
                hiddenWriter.WriteLine(lblColumnC16.Text & ":  " & TextBox16.Text & vbTab & vbTab & vbTab & lblColumnD16.Text)
                hiddenWriter.WriteLine(lblColumnC17.Text & ":  " & TextBox17.Text & vbTab & vbTab & lblColumnD17.Text)
                hiddenWriter.WriteLine(lblColumnC18.Text & ":  " & TextBox18.Text & vbTab & vbTab & vbTab & lblColumnD18.Text)
                hiddenWriter.WriteLine(lblColumnC19.Text & ":  " & TextBox19.Text & vbTab & vbTab & vbTab & lblColumnD19.Text)
                hiddenWriter.WriteLine(lblColumnC20.Text & ":  " & TextBox20.Text)
            ElseIf intQuestionCount = 15 Then
                hiddenWriter.WriteLine("Question:  " & txtQuestion.Text)
                hiddenWriter.WriteLine(lblColumnA1.Text & ":  " & txt1.Text & vbTab & vbTab & lblColumnB1.Text)
                hiddenWriter.WriteLine(lblColumnA2.Text & ":  " & txt2.Text & vbTab & vbTab & vbTab & lblColumnB2.Text)
                hiddenWriter.WriteLine(lblColumnA3.Text & ":  " & txt3.Text & vbTab & vbTab & vbTab & lblColumnB3.Text)
                hiddenWriter.WriteLine(lblColumnA4.Text & ":  " & txt4.Text & vbTab & vbTab & vbTab & lblColumnB4.Text)
                hiddenWriter.WriteLine(lblColumnA5.Text & ":  " & txt5.Text & vbTab & vbTab & lblColumnB5.Text)
                hiddenWriter.WriteLine(lblColumnA6.Text & ":  " & txt6.Text & vbTab & vbTab & lblColumnB6.Text)
                hiddenWriter.WriteLine(lblColumnA7.Text & ":  " & txt7.Text & vbTab & vbTab & lblColumnB7.Text)
                hiddenWriter.WriteLine(lblColumnA8.Text & ":  " & txt8.Text & vbTab & vbTab & lblColumnB8.Text)
                hiddenWriter.WriteLine(lblColumnA9.Text & ":  " & txt9.Text & vbTab & vbTab & lblColumnB9.Text)
                hiddenWriter.WriteLine(lblColumnA10.Text & ":  " & txt10.Text & vbTab & vbTab & lblColumnB10.Text)
                hiddenWriter.WriteLine(lblColumnA11.Text & ":  " & txt11.Text & vbTab & vbTab & lblColumnB11.Text)
                hiddenWriter.WriteLine(lblColumnA12.Text & ":  " & txt12.Text & vbTab & vbTab & lblColumnB12.Text)
                hiddenWriter.WriteLine(lblColumnA13.Text & ":  " & txt13.Text & vbTab & lblColumnB13.Text)
                hiddenWriter.WriteLine(lblColumnA14.Text & ":  " & txt14.Text & vbTab & vbTab & vbTab & lblColumnB14.Text)
                hiddenWriter.WriteLine(lblColumnA15.Text & ":  " & txt15.Text & vbTab & vbTab & lblColumnB15.Text)
                hiddenWriter.WriteLine(lblColumnA16.Text & ":  " & txt16.Text & vbTab & vbTab & lblColumnB16.Text)
                hiddenWriter.WriteLine(lblColumnA17.Text & ":  " & txt17.Text & vbTab & vbTab & lblColumnB17.Text)
                hiddenWriter.WriteLine(lblColumnA18.Text & ":  " & txt18.Text & vbTab & vbTab & lblColumnB18.Text)
                hiddenWriter.WriteLine(lblColumnA19.Text & ":  " & txt19.Text & vbTab & vbTab & lblColumnB19.Text)
                hiddenWriter.WriteLine(lblColumnA20.Text & ":  " & txt20.Text & vbTab & vbTab & lblColumnB20.Text)
                hiddenWriter.WriteLine(lblColumnA21.Text & ":  " & txt21.Text & vbTab & vbTab & lblColumnB21.Text)
                hiddenWriter.WriteLine(lblColumnA22.Text & ":  " & txt22.Text & vbTab & vbTab & lblColumnB22.Text)
                hiddenWriter.WriteLine(lblColumnA23.Text & ":  " & txt23.Text & vbTab & vbTab & lblColumnB23.Text)
                hiddenWriter.WriteLine(lblColumnA24.Text & ":  " & txt24.Text & vbTab & vbTab & lblColumnB24.Text)
            End If
            hiddenWriter.WriteLine()
            If intQuestionCount = 15 Then
                hiddenWriter.WriteLine("Block 3 Section 4 Homework Complete")
                'hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                'hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.Close()

            'MsgBox("Text written to file")
        Else
            MsgBox("File Does Not Exist Results")
        End If

        If intQuestionCount > 0 Then
            txtAnswer.Clear()
        End If

    End Sub

    Private Sub OpenResults()
        Dim p As Process = Process.Start(filename & "\Homework\Block 3\Block 3 Section 4.txt")
    End Sub
    Public Sub writeXmlData()
        Dim writer As New XmlTextWriter("C:\Temp\B3S4AFSData.xml", System.Text.Encoding.UTF8)
        writer.WriteStartDocument(True)
        writer.Formatting = Formatting.Indented
        writer.Indentation = 2
        writer.WriteStartElement("blockthreesectionfour")
        For i = 1 To ArrayMax
            writer.WriteStartElement("Question" & i)
            writer.WriteString(HWQuestions(i, 1))
            writer.WriteEndElement()
            writer.WriteStartElement("Answer" & i)
            writer.WriteString("None")
            writer.WriteEndElement()
            writer.WriteStartElement("Reference" & i)
            writer.WriteString(HWQuestions(i, 3))
            writer.WriteEndElement()
        Next
        writer.WriteEndElement()
        writer.Close()
    End Sub

End Class
